package com.cwz.controller;

import com.cwz.entity.Literature;
import com.cwz.entity.LiteratureRecord;
import com.cwz.param.LiteratureHttpQueryParam;
import com.cwz.param.LiteratureStatisticsParam;
import com.cwz.service.LiteratureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/literature")
public class LiteratureController {

    @Resource
    private LiteratureService literatureService;

    // 保存文献
    @PostMapping("/save")
    public Map<String, Object> save(Literature literature, HttpSession session) {
        return literatureService.save(literature, session);
    }

    // 上传文献
    @PostMapping("/upload")
    public Map<String, Object> upload(MultipartFile file, HttpSession session) {
        return literatureService.upload(file, session);
    }

    // 分页查询文献
    @GetMapping("/page")
    public Map<String, Object> page(LiteratureHttpQueryParam param, HttpSession session) {
        return literatureService.page(param, session);
    }

    // 禁用文献
    @PostMapping("/disable")
    public Map<String, Object> disable(Integer id, HttpSession session) {
        return literatureService.disable(id, session);
    }

    // 查看文献详情
    @GetMapping("/detail")
    public Map<String, Object> detail(Integer id, HttpSession session) {
        return literatureService.detail(id, session);
    }

    // 下载文献
    @GetMapping("/download")
    public void download(Integer id, HttpServletResponse response) {
        literatureService.download(id, response);
    }

    // 统计文献操作记录
    @GetMapping("/statistic")
    public Map<String, Object> statistic(LiteratureStatisticsParam param, HttpSession session) {
        return literatureService.statistic(param, session);
    }
}